﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace PdxDemo
{
    public class ShellViewModel
    {
        public List<ScreenModel> Screens { get; set; }

        public ShellViewModel()
        {
            Screens = new List<ScreenModel>();

            AddScreen(new Conventions.ViewModel(), "Conventions");
            AddScreen(new IDataErrorInfoDemo.ViewModel(), "IDataErrorInfo");
            AddScreen(new FluentValidationDemo.ViewModel(), "FluentValidation");
            AddScreen(new DataAnnotationsDemo.ViewModel(), "DataAnnotations");
            AddScreen(new MasterDetailDemo.ViewModel(), "Master-Detail");

            SelectedScreen = Screens[0];
        }

        void AddScreen(ViewmodelBase viewmodel, string displayName)
        {
            Screens.Add(new ScreenModel() { Viewmodel = viewmodel, DisplayName = displayName });
        }

        ScreenModel _selectedScreen;
        public ScreenModel SelectedScreen
        {
            get { return _selectedScreen; }
            set
            {
                if (_selectedScreen != null)
                {
                    // If we want to allow undo after leaving the screen and coming back,
                    // the easiest way would be to save the view and bypass Caliburn's
                    // behavior of instantiating a new one.
                    _selectedScreen.Viewmodel.ChangeRecorder.Clear();
                }

                _selectedScreen = value;
                //System.GC.Collect();
            }
        }
    }

    public class ScreenModel
    {
        public ViewmodelBase Viewmodel { get; set; }
        public string DisplayName { get; set; }
    }
}
